﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WorldEvolution
{
    public class World : IUpdateable
    {
        static World instance;
        public static World Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new World();
                }
                return instance;
            }
        }

        public void Initialze()
        {
            Time.RegistTime(this);
        }


        public void FixedUpdate()
        {
            _Evolving();
        }

        public void LateUpdate()
        {
            
        }

        public void PreUpdate()
        {
            
        }

        private void _Evolving()
        {
            if (Time.FrameCount % WorldDefine.EvolveFrameRate != 0)
                return;
            if(mRegions.Count == 0)
            {
                Region newRegion = Region.Create();
                mRegions.Add(newRegion);
                newRegion.Evolute();
                History.Instance.PushHistory("天地初开，化生万物！");
            }
            else
            {
                foreach (var r in mRegions)
                    r.Evolute();
                //History.Instance.PushHistory("世界进化中：Frame={0},Time={1}",Time.FrameCount,System.DateTime.Now.Ticks);
            }
            
        }

        List<Region> mRegions = new List<Region>();
    }
}
